home *** CD-ROM | disk | FTP | other *** search
- #
- # chmod.test
- #
- # Tests for the chmod, chown and chgrp commands.
- #---------------------------------------------------------------------------
- # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: chmod.test,v 2.0 1992/10/16 04:49:26 markd Rel $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] != "test"} then {source testlib.tcl}
-
- #-----------------------------------------------------------------------------
- # This routine to the the mode of a file. It is returned formated in octal.
-
- proc GetMode {filename} {
- file stat $filename stat
- return [format "%o" [expr {$stat(mode) & 07777}]]
- }
-
- #-----------------------------------------------------------------------------
- # Certain Unix systems don't handle chmod the same. This routine test if the
- # system chmod produces the expected results.
- # o mode - symbolic mode to set the file to.
- # o expect - expected result from ls.
- #
- proc CheckChmod {mode expect} {
- chmod 000 CHECK.TMP
- exec chmod $mode CHECK.TMP
- set sysMode [lindex [exec ls -l CHECK.TMP] 0]
- return [expr {"$sysMode" == "$expect"}]
- }
-
-
- #-----------------------------------------------------------------------------
- # Procedure to return the uid of a file.
-
- proc GetUID {file} {
- file stat $file stat
- return $stat(uid)
- }
-
- #-----------------------------------------------------------------------------
- # Procedure to return the gid of a file.
-
- proc GetGID {file} {
- file stat $file stat
- return $stat(gid)
- }
-
- #-----------------------------------------------------------------------------
- # Procedure to return the uid and gid of a file.
-
- proc GetUIDGID {file} {
- file stat $file stat
- return [list $stat(uid) $stat(gid)]
- }
-
-
- #-----------------------------------------------------------------------------
- # If a user does not have a group name assigned, then some tests will not work,
- # just blow off the tests and let the user make things right.
-
- if {[catch {id group}] != 0} {
- echo "User '[id user]' does not have group name. Chmod tests skipped"
- return
- }
-
- #-----------------------------------------------------------------------------
- # Purge existing test files and recreate them.
- #
- proc SetUpTestFiles {} {
- foreach f {CHECK.TMP CHMOD.TMP CHMOD2.TMP} {
- unlink -nocomplain $f
- close [open $f w]
- }
- }
-
- SetUpTestFiles
-
- # Set the umask so that no bits are masked. Some system chmods use umask
- # if u, g, o or a are not specified in a symbolic chmod.
-
- umask 000
-
- Test chmod-1.1 {chmod absolute mode tests} {
- chmod 0000 CHMOD.TMP
- chmod 0101 CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {101}
-
- Test chmod-1.2 {chmod absolute mode tests} {
- chmod 0000 CHMOD.TMP
- chmod 0010 CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {10}
-
- Test chmod-1.3 {chmod absolute mode tests} {
- chmod 0000 CHMOD.TMP
- chmod 0777 CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {777}
-
- Test chmod-1.4 {chmod absolute mode tests} {
- chmod 0000 CHMOD.TMP
- chmod 0666 CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {666}
-
- Test chmod-1.5 {chmod absolute mode tests} {
- chmod 0000 CHMOD.TMP
- chmod 0705 CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {705}
-
- Test chmod-1.7 {chmod absolute mode tests} {
- chmod 0000 CHMOD.TMP
- chmod 04111 CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {4111}
-
- Test chmod-2.1 {chmod absolute integer mode tests} {
- chmod 0 {CHMOD.TMP CHMOD2.TMP}
- chmod 65 {CHMOD.TMP CHMOD2.TMP}
- list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
- } 0 {101 101}
-
- Test chmod-2.2 {chmod absolute integer mode tests} {
- chmod 0 {CHMOD.TMP CHMOD2.TMP}
- chmod 8 {CHMOD.TMP CHMOD2.TMP}
- list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
- } 0 {10 10}
-
- Test chmod-2.3 {chmod absolute integer mode tests} {
- chmod 0 {CHMOD.TMP CHMOD2.TMP}
- chmod 511 {CHMOD.TMP CHMOD2.TMP}
- list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
- } 0 {777 777}
-
- Test chmod-2.4 {chmod absolute integer mode tests} {
- chmod 0 {CHMOD.TMP CHMOD2.TMP}
- chmod 438 {CHMOD.TMP CHMOD2.TMP}
- list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
- } 0 {666 666}
-
- Test chmod-2.5 {chmod absolute integer mode tests} {
- chmod 0 {CHMOD.TMP CHMOD2.TMP}
- chmod 453 {CHMOD.TMP CHMOD2.TMP}
- list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
- } 0 {705 705}
-
- Test chmod-2.6 {chmod absolute integer mode tests} {
- chmod 0 CHMOD.TMP
- chmod 2121 CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {4111}
-
- # Test symbolic mode.
-
- Test chmod-3.1 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod +r CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {444}
-
- Test chmod-3.2 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod +r CHMOD.TMP
- chmod +w CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {666}
-
- Test chmod-3.3 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod +r CHMOD.TMP
- chmod +w CHMOD.TMP
- chmod +x CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {777}
-
- Test chmod-3.4 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod +r CHMOD.TMP
- chmod +w CHMOD.TMP
- chmod +x CHMOD.TMP
- chmod -r CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {333}
-
- Test chmod-3.5 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod +r CHMOD.TMP
- chmod +w CHMOD.TMP
- chmod +x CHMOD.TMP
- chmod -r CHMOD.TMP
- chmod -w CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {111}
-
- Test chmod-3.6 {chmod symbolic mode tests} {
- chmod 000 {CHMOD.TMP CHMOD2.TMP}
- chmod +r {CHMOD.TMP CHMOD2.TMP}
- chmod +w {CHMOD.TMP CHMOD2.TMP}
- chmod +x {CHMOD.TMP CHMOD2.TMP}
- chmod -r {CHMOD.TMP CHMOD2.TMP}
- chmod -w {CHMOD.TMP CHMOD2.TMP}
- chmod -x {CHMOD.TMP CHMOD2.TMP}
- list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
- } 0 {0 0}
-
- Test chmod-3.7 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod u+x,g+x CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {110}
-
- Test chmod-3.8 {chmod symbolic mode tests} {
- chmod 000 {CHMOD.TMP CHMOD2.TMP}
- chmod u+x,g+x {CHMOD.TMP CHMOD2.TMP}
- chmod u-x,g-x {CHMOD.TMP CHMOD2.TMP}
- list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
- } 0 {0 0}
-
- # Can't +s on some systems
-
- if [CheckChmod "ugo+x,ug+s" "---s--s--x"] {
- Test chmod-3.9 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod ugo+x,ug+s CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {6111}
- }
-
- Test chmod-3.10 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod a+rwx CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {777}
-
- Test chmod-3.11 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod a+rwx CHMOD.TMP
- chmod a-rw CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {111}
-
- Test chmod-3.12 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod a=rwx CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {777}
-
- Test chmod-3.13 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod u=rwx,go=rx CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {755}
-
- Test chmod-3.14 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod u+t CHMOD.TMP
- set mode [GetMode CHMOD.TMP]
- expr "($mode == 0) || ($mode == 1000)"
- } 0 {1}
-
- # +t is dificult to test if not root, just make sure it execute and hope
- # for the best.
-
- Test chmod-3.14 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod u+t CHMOD.TMP
- } 0 {}
-
- Test chmod-3.15 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod u+t CHMOD.TMP
- chmod u-t CHMOD.TMP
- } 0 {}
-
- Test chmod-3.16 {chmod symbolic mode tests} {
- chmod 000 CHMOD.TMP
- chmod a+rwx CHMOD.TMP
- chmod u-r,g-w,o-x CHMOD.TMP
- GetMode CHMOD.TMP
- } 0 {356}
-
- Test chmod-4.1 {chmod error tests} {
- chmod +z CHMOD.TMP
- } 1 {invalid file mode "+z"}
-
- Test chmod-4.2 {chmod error tests} {
- chmod
- } 1 {wrong # args: chmod mode filelist}
-
- # chown and chgrp tests
-
- #
- # Some machines have problems with changing group ids on files (even to your
- # own) if you are not root. If thats the case, bail out here.
- #
-
- SetUpTestFiles
-
-
- if {[catch {chgrp [id groupid] CHMOD.TMP} msg ] != 0} {
- puts stderr "*************************************************************"
- puts stderr "Can't do chgrp even when current and new group id are"
- puts stderr "ours. Maybe a strange system."
- puts stderr " $msg"
- puts stderr "*************************************************************"
- unlink {CHECK.TMP CHMOD.TMP CHMOD2.TMP}
- return
- }
-
- set myUID [id userid]
- set myGID [id groupid]
-
- Test chmod-5.1 {chown tests} {
- SetUpTestFiles
- chown [id user] {CHMOD.TMP CHMOD2.TMP}
- list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
- } 0 [list $myUID $myUID]
-
- Test chmod-5.2 {chown tests} {
- chown [id userid] {CHMOD.TMP CHMOD2.TMP}
- list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
- } 0 [list $myUID $myUID]
-
- Test chmod-5.3 {chown tests} {
- chown [list [id userid] [id groupid]] {CHMOD.TMP CHMOD2.TMP}
- list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
- } 0 [list [list $myUID $myGID] [list $myUID $myGID]]
-
- Test chmod-5.4 {chown tests} {
- chown [list [id user] [id group]] {CHMOD.TMP CHMOD2.TMP}
- list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
- } 0 [list [list $myUID $myGID] [list $myUID $myGID]]
-
- Test chmod-5.5 {chown tests} {
- chown [list [id user] [id group]] {CHMOD.TMP CHMOD2.TMP}
- list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
- } 0 [list [list $myUID $myGID] [list $myUID $myGID]]
-
- SetUpTestFiles
-
- Test chmod-6.1 {chown error tests} {
- chown XXXXXXXXX CHMOD.TMP
- } 1 {unknown user id: XXXXXXXXX}
-
- Test chmod-6.2 {chown error tests} {
- chown [list XXXXXXXXX [id groupid]] CHMOD.TMP
- } 1 {unknown user id: XXXXXXXXX}
-
- Test chmod-6.3 {chown error tests} {
- chown [list [id user] XXXXXXXXX] CHMOD.TMP
- } 1 {unknown group id: XXXXXXXXX}
-
- Test chmod-6.4 {chown error tests} {
- chown {XXXXXXXXX YYYY} CHMOD.TMP
- } 1 {unknown user id: XXXXXXXXX}
-
- Test chmod-6.5 {chown error tests} {
- chown
- } 1 {wrong # args: chown owner|{owner group} filelist}
-
- Test chmod-7.1 {chgrp tests} {
- chgrp [id group] {CHMOD.TMP CHMOD2.TMP}
- list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
- } 0 [list $myGID $myGID]
-
- Test chmod-7.2 {chgrp tests} {
- chgrp [id groupid] {CHMOD.TMP CHMOD2.TMP}
- list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
- } 0 [list $myGID $myGID]
-
- Test chmod-8.1 {chgrp error tests} {
- chgrp
- } 1 {wrong # args: chgrp group filelist}
-
- Test chmod-8.2 {chgrp error tests} {
- chgrp XXXXXXXXX CHMOD.TMP
- } 1 {unknown group id: XXXXXXXXX}
-
- unlink {CHECK.TMP CHMOD.TMP CHMOD2.TMP}
-
-